<template>
  <view class="container">
    

    <!-- 居中的搜索栏 -->
    <view class="search-bar">
      <input class="search-input" type="text" placeholder="请输入搜索内容">
      <button class="search-button">搜索</button>
    </view>

    <!-- 宠物视频列表 -->
    <view v-for="pet in petList" :key="pet.petId" class="pet-info" @click="goToPetDetails(pet.petId)">
      <video class="pet-video" :src="getVideoUrl(pet.video)" type="video/mp4">
        
      </video>
      <view class="pet-details">
        <text class="pet-name">{{ pet.petName }}</text>
        <text class="pet-description">{{ pet.description }}</text>
        <text class="pet-price">¥ {{ pet.price }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import config from '@/config';  // 引入config来设置全局的东西

export default {
  data() {
    return {
      petList: []  // 存储从后端获取的宠物数据
    };
  },
  mounted() { 
    // 在组件挂载后获取后端数据
    this.fetchPetData();
  },
  methods: { 
    fetchPetData() {
      // 使用 uni.request 获取后端数据
      uni.request({
        url: config.apiUrl + '/pet/getall',
        method: 'GET',
        success: (response) => {
          this.petList = response.data; // 将后端返回的宠物数据存储到 petList 中
        console.log(this.petList)
		},
        fail: (error) => {
          console.error('Error fetching pet data:', error);
        }
      });
    },
    getVideoUrl(videoPath) {
      // 拼接视频路径
      return videoPath;
    },
    goToPetDetails(petId) {
		console.log("21334432")
      uni.navigateTo({
        url: `/pages/petDetail/petDetail?petId=${petId}`
      });
    }
  }
};
</script>

<style scoped>

.container {
  padding: 10px;
  background-color: #ffefba;
  border-bottom: 1px solid #ccc;
}

.logo-content {
  display: flex;
  justify-content: space-between; /* 水平分散对齐 */
  align-items: center; /* 垂直居中 */
}

.logo-title {
  display: flex;
  align-items: center; /* 垂直居中 */
}

.title {
  font-size: 38rpx;
  margin-left: 20rpx;
}

.map-icon {
  display: flex;
  align-items: center; /* 垂直居中 */
}

.map-text {
  font-size: 32rpx;
  margin-left: 10rpx;
}

.logo-image {
  width: 100rpx; /* 调整图片宽度 */
  height: 100rpx; /* 调整图片高度 */
}

.map-image {
  width: 40rpx; /* 调整地图图标宽度 */
  height: 40rpx; /* 调整地图图标高度 */
}

.search-bar {
  margin-top: 20px; /* 距离上方的间距 */
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
}

.search-input {
  padding: 8px;
  font-size: 16px;
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 18px;
  margin-right: 8px;
  width: 250px;
}

.search-button {
  height: 40px;
  font-size: 16px;
  background-color: #4CAF50; /* 绿色背景 */
  color: white;
  border: none;
  border-radius: 18px;
  cursor: pointer;
}

.pet-info {
  display: flex;
  flex-direction: column;
  margin-top: 20px;
  background-color: aliceblue;
  border-radius: 18px; /* 设置圆角 */
}

.pet-video {
  width: 100%;
  justify-content: center;
}

.pet-details {
  padding: 10px;
}

.pet-name {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
  display: block; /* 每个商品信息占据一行 */
} 

.pet-description {
  font-size: 12px;
  color: #666; 
  margin-bottom: 10px;
  display: block; /* 每个商品信息占据一行 */
}

.pet-price {
  font-size: 16px;
  font-weight: bold;
  color: #f00;
  display: block; /* 每个商品信息占据一行 */
}
</style>
